package com.hudongwx.godoffood.activity.Shopping_Activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hudongwx.godoffood.R;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

/**
 * 配送的页面
 */
@ContentView(R.layout.activity_distribution)
public class DistributionActivity extends AppCompatActivity {
@ViewInject(R.id.distribution_ll)
    LinearLayout linearLayout;
    @ViewInject(R.id.distribution_tv_1)
    TextView textView1;
    @ViewInject(R.id.distribution_tv_2)
    TextView textView2;
    @ViewInject(R.id.distribution_tv_3)
    TextView textView3;
    String string;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);

    }

    @Event(R.id.distribution_img)
    private void OnClick(View view){
        finish();
    }

    /**
     * 只能单选
     * @param view
     */
    @Event(value = {R.id.distribution_tv_1,R.id.distribution_tv_2,R.id.distribution_tv_3})
    private void OnClick_tv(View view){
        if (!view.isSelected()) {
            for (int i = 0; i < linearLayout.getChildCount(); i++) {
                linearLayout.getChildAt(i).setSelected(false);

            }
            view.setSelected(true);
        } else {
            view.setSelected(false);
        }
        switch (view.getId()){
            case R.id.distribution_tv_1:
                string = (String) textView1.getText();
                break;
            case R.id.distribution_tv_2:
                string = (String) textView2.getText();
                break;
            case R.id.distribution_tv_3:
                string = (String) textView3.getText();
                break;
        }
        Intent intent=new Intent(DistributionActivity.this,ConfirmActivity.class);
        intent.putExtra("distribution",string);
        setResult(2,intent);
        finish();
    }

}
